<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap-switch.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/font-awesome/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/static/datepicker/css/datepicker.css"/>
    <style type="text/css">
        body {
            background: #EFF3FC
        }

        html, body, .content {
            height: 100%;
        }

        .content {
            margin-left: 0;
            margin-top: 0;
            width: 98%;
            margin: 0 auto;
            padding: 0px 20px 0 20px;
        }

        table {
            width: 90%;
            margin: 0 auto;
        }

        tr {
            height: 35px;
            text-align: center;
        }

        tr:first-child {
            background: #cccccc;
            text-align: center;
        }

        tr th {
            text-align: center;
        }

        button, input {
            line-height: normal;
        }

        .archiveChance {
            height: 90px;
            background: #FFFFFF;
            border-radius: 5px;
            margin-bottom: 17px;
        }

        .archiveChance > div {
            padding: 10px 31px;
        }

        .archiveChance > div span {
            padding-right: 20px;
        }

        .archiveClass {
            height: 78%;
            background: #FFFFFF;
            overflow-y: scroll;
            overflow-x: hidden;
        }

        .archiveClass > div {
            padding-top: 20px;
            padding-bottom: 20px;
            padding-left: 31px;
        }

        .add-btn {
            border: 2px solid #45CEF6;
            border-radius: 5px;
            background-color: #fff;
        }

        .add-box {
            position: absolute;
            top: 54%;
            width: 30px;
            transform: translate(0, -50%);
            text-align: center;
        }

        .icon-plus {
            display: inline-block;
            height: 100%;
            vertical-align: middle;
            font-size: 18px;
            color: #45CEF6;
            font-weight: bold;
        }

        .tabList {
            width: 80%;
            margin: 0 auto;
        }
    </style>
</head>
<body ng-app="logMag" ng-controller="logManageCtrl">
<div class="content">
    <div style="padding: 10px 0;">系统管理>归档配置</div>
    <div class="archiveChance">
        <div>
            <span>默认归档：</span>
            <div class="switch  has-switch bootstrap-switch-mini bootstrap-switch-id-switch-size bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-off"
                 data-on="info" data-off="success" style="display:inline-block" id="default_archive-sw">
                <input type="checkbox" id="default_archive" checked name="default_archive"/>
            </div>
        </div>
        <div>
            <span>智能归档：</span>
            <div class="switch  has-switch bootstrap-switch-mini bootstrap-switch-id-switch-size bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-off "
                 data-on="info" data-off="success" style="display:inline-block" id="smart_archive-sw">
                <input type="checkbox" checked id="smart_archive" name="smart_archive"/>
            </div>
        </div>
    </div>
    <div class="archiveClass">
        <div class="row">
            <lable class="col-sm-1">归档分类:</lable>
            <div class="col-sm-2">
                <input type="text" class="form-control" placeholder="输入分类名称，必填" ng-model="archiveForm.name">
            </div>
            <div class="col-sm-2">
                <input type="text" class="form-control" placeholder="输入分类编码，必填" ng-model="archiveForm.code">
            </div>
            <div class="col-sm-2">
                <input type="text" class="form-control" placeholder="输入排序" ng-model="archiveForm.sort">
            </div>
            <div class="col-sm-3">
                <input type="text" class="form-control" placeholder="输入智能归档关键字，多关键字用逗号隔开"
                       ng-model="archiveForm.keywords">
            </div>
            <div class="col-sm-1" style="height:34px;;">
                <div class="add-box">
                    <button class="add-btn add-box" ng-click="addArchive(archiveForm)">
                        <i class="fa fa-plus icon-plus"></i>
                    </button>
                </div>
            </div>
        </div>
        <table class="col-sm-12 table table-striped tabList">
            <thead>
            <tr>
                <td>名称</td>
                <td>编码</td>
                <td>排序</td>
                <td>关键字</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="item in dataList">
                <td>{$ item.name $}</td>
                <td>{$ item.code $}</td>
                <td>{$ item.sort $}</td>
                <td>{$ item.keywords $}</td>
                <td class="pointer">
              	<span title="删除">
              		<a ng-click="deleteArchive(item.id)"><i class="fa fa-trash"></i></a>
              	</span>
                    <span title="编辑">
              		<a ng-click="editArchive(item.id)"><i class="fa fa fa-pencil "></i></a>
              	</span>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <!--<div id="demo7" class="pag"></div>-->
</div>

<!-- 删除用户模态框 -->
<div class="modal fade" id="delArchiveModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">删除分类</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12">
                        删除不可恢复,是否确认删除?
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                </button>
                <button type="button" class="btn btn-primary" ng-click="delArchiveOK(id)">
                    确认
                </button>
            </div>
        </div>
    </div>
</div>
<!--编辑归档分类模态框-->
<div class="modal fade" id="editArchive" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    {{ modalTitle }}
                </h4>
            </div>
            <div class="modal-body">
                <input type="hidden" name="addOrEdit" id="addOrEdit" value=""/>
                <div class="row">
                    <div class="col-sm-12">
                        <form role="form" class="form-horizontal">
                            <div class="form-group">
                                <label for="firstName" class="col-sm-3 control-label"><span
                                        style="color:#ff0000">*</span>分类名称</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="firstName"
                                           ng-model="archiveEditForm.name">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="pwd" class="col-sm-3 control-label"><span style="color:#ff0000">*</span>分类编码</label>
                                <div class="col-sm-6">
                                    <input type="password" class="form-control" id="pwd"
                                           ng-model="archiveEditForm.code" maxlength="30">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="name" class="col-sm-3 control-label">排序</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="name" ng-model="archiveEditForm.sort">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="department" class="col-sm-3 control-label">归档关键字</label>
                                <div class="col-sm-6">
                                    <input type="text" ng-click="chanceTree()" ng-model="archiveEditForm.keywords"
                                           name=""
                                           id="" value="" class="form-control"/>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                </button>
                <button type="button" class="btn btn-primary" ng-click="editArchiveOk(archiveEditForm)">
                    确认
                </button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/assets/js/jquery-3.1.0.js"></script>
<script type="text/javascript" src="/static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/bootstrap/js/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/static/assets/js/bui-min.js"></script>
<script type="text/javascript" src="/static/datepicker/js/datepicker.all.js"></script>
<script type="text/javascript" src="/static/plugins/angular/angular.min.js"></script>
<script type="application/javascript" src="/static/datepicker/js/moment.min.js"></script>
<script type="text/javascript" src="/static/assets/js/config-min.js"></script>
<script type="text/javascript" src="/static/plugins/layui/js/layui.js"></script>
<script type="text/javascript">
    $("[name='default_archive']").bootstrapSwitch({
        onSwitchChange: function (event, state) {
            console.log("event", event);
            if (state == true) {
                state = 1
            } else {
                state = 0
            }
            $.ajax({
                url: "/api/archiveClasses/defaultArchive",
                data: JSON.stringify({"default_archive": state}),
                dataType: "json",
                method: "POST",
                success: function (res) {

                }
            })
        }
    });
    $("[name='smart_archive']").bootstrapSwitch({
        onSwitchChange: function (event, state) {
            console.log("event", event);
            if (state == true) {
                state = 1
            } else {
                state = 0
            }
            $.ajax({
                url: "/api/archiveClasses/smartArchive",
                data: JSON.stringify({"smart_archive": state}),
                dataType: "json",
                method: "POST",
                success: function (res) {

                }
            })
        }
    });

    $('#default_archive').bootstrapSwitch('state', {{ default_archive }} == 1
    )
    ;
    $('#smart_archive').bootstrapSwitch('state', {{ smart_archive }} == 1
    )
    ;
</script>
<script type="text/javascript">
    var app = angular.module('logMag', []);
    app.config(function ($interpolateProvider) {
        $interpolateProvider.startSymbol('{$');
        $interpolateProvider.endSymbol('$}');
    });
    app.controller('logManageCtrl', function ($scope, $http) {
        $scope.addArchive = addArchiveFun;//归档分类添加
        $scope.deleteArchive = deleteArchiveFun;//删除回档分类
        $scope.editArchive = editArchiveFun;//编辑归档分类
        $scope.archiveForm = {
            name: "",
            code: "",
            sort: "",
            keywords: ""
        };
        $scope.archiveEditForm = {
            name: "",
            code: "",
            sort: "",
            keywords: ""
        };

        //获取列表数据
        $scope.dataListFun = function () {
            console.log("tainjia");
            $http.post('/api/archiveClasses/list').then(
                function (resp) {
                    $scope.dataList = resp.data.data;
                    console.log("3333" + JSON.stringify(resp.data.data))
                },
                function (resp) {
                    alert("接口请求失败");
                });
        };
        $scope.dataListFun();


        function addArchiveFun(form) {
            $http.post('/api/archiveClasses/add', form).then(
                function (resp) {
                    console.log("添加成功");
                    $scope.archiveForm = {
                        nameClass: "",
                        codeClass: "",
                        sort: "",
                        keyword: ""
                    };
                    $scope.dataListFun();
                },
                function (resp) {
                    alert("接口请求失败");
                });
        }

        //删除回档分类
        function deleteArchiveFun(id) {
            $('#delArchiveModal').modal();
            // 确认删除部门
            $scope.delArchiveOK = function () {
                $http({
                    method: 'POST',
                    url: '/api/archiveClasses/delete',
                    data: {
                        "id": id
                    },
                }).then(function successCallback(response) {
                    console.log("删除成功");
                    $scope.dataListFun();
                    // 请求成功执行代码
                }, function errorCallback(response) {
                    console.log("删除失败");
                    // 请求失败执行代码
                });
                $('#delArchiveModal').modal('hide');
            };
        }

        //编辑归档分类
        function editArchiveFun(id) {
            $scope.modalTitle = "编辑归档分类";
            $('#editArchive').modal();
            $http({
                method: 'POST',
                url: '/api/archiveClasses/info',
                data: {
                    "id": id
                },
            }).then(function successCallback(response) {
                $scope.archiveEditForm = response.data.data;
                // 请求成功执行代码
            }, function errorCallback(response) {
                console.log("编辑失败");
                // 请求失败执行代码
            });
        };

        //编辑确认
        $scope.editArchiveOk = function (form) {
            $('#editArchive').modal("hide");
            $http.post('/api/archiveClasses/update', form).then(
                function (resp) {
                    $scope.dataListFun();
                    $scope.archiveEditForm = {
                        nameClass: "",
                        codeClass: "",
                        sort: "",
                        keyword: ""
                    };
                },
                function (resp) {
                    alert("接口请求失败");
                });
        }
    });

</script>
</body>
</html>  